package com.common.pattern.pipeline.service;

import com.common.pattern.pipeline.Result;
import com.common.pattern.pipeline.bo.PipelineContext;
import com.common.pattern.pipeline.config.PipelineExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @Author: xuxiang
 * @Date: 2023-8-10
 * @Description:
 */

public class ExecutorService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    private PipelineExecutor pipelineExecutor;

    public Result<String> dealSync(PipelineContext pipelineContext) {
        if (Objects.isNull(pipelineContext)) {
            return Result.fail("数据异常");
        }
        boolean success = pipelineExecutor.acceptSync(pipelineContext);
        if (success) {
            return Result.ok(pipelineContext.getModelId().toString());
        }
        logger.error("管道处理失败：{}", pipelineContext.getFailureMsg());
        return Result.fail(pipelineContext.getFailureMsg());
    }

}